package com.bos.mapper;

import com.bos.data.model.AccessTokenModel;
import com.bos.data.model.BosUserModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;


public interface AccessTokenMapper {
    //-------------对AccessToken表进行的操作---------------------------------
    //1.将数据插入到AccessToken中
    @Insert("insert into AccessToken(token,expiresIn,saveDate, type) values(#{token},#{expiresIn},#{saveDate},#{type})")
    public int insertAccessToken(AccessTokenModel as);

    //2.查询出AccessToken中的值
    @Select("select * from AccessToken where type=#{type}")
    public List<AccessTokenModel> findAccessToken(String type);

    //3.根据type(accessToken类型) 去修改Access_token中的token 和saveDate
    @Update("update AccessToken set token=#{token},saveDate=#{saveDate} where type=#{type}")
    public int updateByExpirIn(AccessTokenModel acce);

    //4.将用户信息保存到数据库表bos_user中
    @Insert("<script> insert into bos_user(userId,name,mobile,power,department,email,position,gender,status,entryTime,password) " +
            "values <foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\">  " +
            "(#{item.userId},#{item.name},#{item.mobile},#{item.power},#{item.department},#{item.email},#{item.position},#{item.gender},#{item.status},#{item.entryTime},#{item.password})" +
            "</foreach> </script>")
    public int insertUsers(@Param("list") List<HashMap<String, Object>> list);

    //5.查询出用户表中的数据
    @Select("select * from bos_user")
    public List<BosUserModel> findUsers();

    //6。根据名字去获取用户表中的数据
    @Select("select * from bos_user where name=#{name}")
    public BosUserModel findUserByName(String name);
}
